import { Http } from './http';
export class LayoutGrid extends Http {
    gap: number;
    #areas: string[][]
    area: string
    #maxwidths: number[];
    index: number;
    row: number;
    col: number;
    totalWidth: number;
    height: string;
    fontSize: string;
    fontSizes: string[];

    constructor() {
        super()
        this.gap = 10
        this.fontSize = '16px'
        this.fontSizes = ['16px']
        this.#areas = [
            ["a b b c", "d d e e"],
            ["a b c c", "d d e e"],
            ["a a b c", "d d e e"],
            ["a a b c", "d d e e"]
        ]
        this.index = 0
        this.row = 2
        this.col = 4
        this.area = ""
        this.height = '100%'
        this.#maxwidths = [500, 1000, 1500, 1900]
        this.totalWidth = 0
    }
    setWidths(widths: number[]) {
        this.#maxwidths = widths.sort((a, b) => a - b)
    }
    /**
     * 
     * @param areas areas 二维数组，每一项为一个状态，里面每一项为一行，每一行由空格分隔
     */
    setAreas(areas: string[][]) {
        this.#areas = areas
    }
    setTotalWidth(value: number) {
        if (!value) return
        if (this.#areas.length !== this.#maxwidths.length) throw new Error('areas和maxwidths的长度必须相同')
        let index = this.#maxwidths.length - 1
        for (let i = 0; i < this.#maxwidths.length; i++) {
            if (value <= this.#maxwidths[i]) {
                index = i
                break
            }
        }
        this.area = `"${this.#areas[index].toString().replaceAll(",", '""')}"`
        this.row = this.#areas[index].length
        this.col = this.#areas[index][0].split(" ").length
        this.totalWidth = value
        this.fontSize = this.fontSizes[index] || this.fontSizes[this.fontSizes.length - 1]
        this.index = index
    }
}